<template>
<!--  <h2>档案资源</h2>-->
  <div class="app-container">
    <el-row :gutter="10" class="mb8" ref="refbut">
      <el-col :span="24" :xs="24">
        <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
          <el-tab-pane label="个人库" name="personal">
            <el-form :model="personalParams" ref="personalForm"  :inline="true" v-show="showPersonalSearch">
              <el-form-item label="综合检索" prop="personalKeyword">
                <el-input v-model="personalKeyword" placeholder="请输入关键字" clearable/>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search"  @click="personalQuery">查询</el-button>
                <el-button icon="el-icon-refresh"  @click="personalReset">重置</el-button>
              </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8" ref="refbut">
              <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete"  @click="handleDelete"  v-hasPermi="['archive:da:library:remove']">删除</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-folder-add"  @click="handlePublic" v-hasPermi="['archive:da:library:edit:communal']" >提升至公共库</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-folder-add"  @click="handleSpecial" v-hasPermi="['archive:da:library:zt:add']" >添加至专题库</el-button>
              </el-col>
              <right-toolbar :showSearch.sync="showPersonalSearch" @queryTable="getPersonalList"></right-toolbar>
            </el-row>
            <el-table v-loading="personalLoading" :data="personalList" :height="tableHeight" @selection-change="personalSelectionChange" @cell-dblclick="celldblclick">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" type="index" :index="table_index_personal" width="55" align="center" prop="ID"/>
              <el-table-column label="档号" align="center" prop="DH"/>
              <el-table-column label="题名" prop="TITLE" align="center" />
              <el-table-column label="年度" prop="ND" align="center" />
              <el-table-column label="密级" prop="MJ" align="center" />
              <el-table-column label="保管期限" prop="BGQX" align="center" />
            </el-table>
            <pagination v-show="personalTotal > 0" :total="personalTotal" :page.sync="personalParams.pageNum"
                        :limit.sync="personalParams.pageSize" @pagination="getPersonalList" />
          </el-tab-pane>

          <el-tab-pane label="公共库" name="public">
            <el-card class="box-card">
              <div style="display: flex; float: right;">
                <el-button v-if="showCategory" type="primary" plain icon="el-icon-arrow-up" size="mini" @click="fold">折叠
                </el-button>
                <el-button v-else type="primary" plain icon="el-icon-arrow-down" size="mini" @click="expand">展开
                </el-button>
              </div>
              <el-row :gutter="10" class="mb8" ref="refbut" v-show="showCategory" style="width: 95%;">
                <div class="searchCheck">
                  <div style="width: 8%">
                    <label style="width: 80%; display: inline-block; text-align-last: justify;">档案门类</label><font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
                  </div>
                  <div style="display: flex; flex-wrap: wrap; width: 90%">
                    <div class="block" v-for="(item,index) in archiveData" :key="item.value" @click="handleCategory(index, item)" :style="{ color: item.color, backgroundColor: item.backgroundColor }">
                      {{ item.label }}
                    </div>
                  </div>
                </div>
                <el-form ref="queryForm" :size="size1" :inline="true" v-show="showSearch">
                  <el-form-item label="" v-for="(item, index) in listFrom" :key="index">
                    <span slot="label">{{ item.FIELD_CAPTION }} </span>
                    <Input :item="item" :listFrom="listFrom" @onChangeTap="onChangeTap" :inputType="1" :sourceType="1" @handleQuery="handleQuery"
                                :inputParams="queryParam" />
                  </el-form-item>
                </el-form>
                <div class="searchCheck">
                  <div style="width: 8%">
                    <label style="width: 80%; display: inline-block; text-align-last: justify;">综合查询</label><font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
                  </div>
                  <div style="display: flex; width: 50%">
                    <el-input v-model="keyword" placeholder="请输入关键字" :maxlength="100" style="width: 90%"/>
                  </div>
                  <div>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                  </div>
                </div>
<!--                <queryCriteriaList :showSearch="showSearch" :listFrom="listFrom"-->
<!--                                   @resetQuery="resetQuery" @handleQuery="handleQuery" ref="queryForm"></queryCriteriaList>-->
              </el-row>
              <div class="showtable">
                <el-row :gutter="10" class="mb8" ref="refbut">
                  <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus"  @click="returnPersonal" v-hasPermi="['archive:da:library:edit:communal']" >退回至个人库</el-button>
                  </el-col>
                </el-row>
                <tableList v-if="tableHeight && tableHeaderList.length > 0" :tableHeaderList="tableHeaderList" ref="tableList" :sourceType="'1'" :isBianyan="true"
                           @handleSelectionChange="handleSelectionChange" :tableData="tableData" :loading="loading" @celldblclick="celldblclick"
                           :tableHeight="tableHeight > 470 ? 470 : tableHeight" @sortChange="sortChange"
                ></tableList>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                            :limit.sync="queryParams.pageSize" @pagination="getQuery" />
              </div>
            </el-card>
          </el-tab-pane>


          <el-tab-pane label="专题库" name="special">
            <el-row :gutter="20">
              <el-col :span="4" :xs="24" ref="hMain">
                <div class="head-container" :style="{height: treeHeight+'px'}" style="overflow: auto">
                  <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                           :filter-node-method="filterNode" :default-expanded-keys="expandedkeys"
                           :current-node-key="currentNodekey" ref="tree" node-key="typeId" default-expand-all highlight-current
                           @node-click="handleNodeClick">
                    <template slot-scope="{ node, data }">
                      <span class="span-ellipsis" :title="node.label" :style="size">{{ node.label }}</span>
                    </template>
                  </el-tree>
                </div>
              </el-col>

              <el-col :span="20" :xs="24" v-show="isShow">
                <el-form :model="specialParams" ref="specialForm"  :inline="true" v-show="showSpecialSearch">
                  <el-form-item label="综合检索" prop="specialKeyword">
                    <el-input v-model="specialKeyword" placeholder="请输入关键字" clearable/>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" icon="el-icon-search"  @click="specialQuery">查询</el-button>
                    <el-button icon="el-icon-refresh"  @click="specialReset">重置</el-button>
                  </el-form-item>
                </el-form>
                <el-row :gutter="10" class="mb8" ref="refbut">
                  <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-folder-add"  @click="returnPerson" v-hasPermi="['archive:da:library:removeCommunal:communal']" >退回至个人库</el-button>
                  </el-col>
                  <right-toolbar :showSearch.sync="showSpecialSearch" @queryTable="getSpecialList"></right-toolbar>
                </el-row>
                <el-table v-loading="specialLoading" :data="specialList" :height="tableHeight" @selection-change="specialSelectionChange" @cell-dblclick="celldblclick">
                  <el-table-column type="selection" width="55" align="center" />
                  <el-table-column label="序号" type="index" :index="table_index_special" width="55" align="center" prop="ID"/>
                  <el-table-column label="档号" align="center" prop="DH" :show-overflow-tooltip="true" />
                  <el-table-column label="题名" prop="TITLE" align="center" :show-overflow-tooltip="true" />
                  <el-table-column label="年度" prop="ND" align="center" :show-overflow-tooltip="true" />
                  <el-table-column label="密级" prop="MJ" align="center" :show-overflow-tooltip="true" />
                  <el-table-column label="保管期限" prop="BGQX" align="center" :show-overflow-tooltip="true" />
                </el-table>
                <pagination v-show="specialTotal > 0" :total="specialTotal" :page.sync="specialParams.pageNum"
                            :limit.sync="specialParams.pageSize" @pagination="getSpecialList" />
              </el-col>
              <el-col :span="20" :xs="24" v-show="!isShow" class="empty">
                <el-empty :image-size="200"></el-empty>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>


    <!-- 添加专题库 -->
    <el-dialog title="添加至专题库" :visible.sync="specialOpen" width="30%" append-to-body>
      <div style="overflow-y: auto; height: 250px">
        <el-tree ref="categoryTree" :data="treeData" node-key="typeId" :props="defaultProps" @node-click="specialClick" default-expand-all>
        </el-tree>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitSpecial">确 定</el-button>
        <el-button @click="specialCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--start  组件详情 -->
    <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
                     @detailsHandleClose="detailsHandleClose">
    </jianDetailsOpen>
    <!--end 组件详情 -->
    <!-- start 组卷\项目详情 -->
    <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData"
                     @detailsHandleClose="detailsHandleClose"></juanDetailsOpen>
    <!-- end 组卷\项目详情 -->
  </div>
</template>

<script>
import treeHeight from "@/mixins/treeHeight";
import estimateTableHeight from "@/mixins/estimateTableHeight";
import {getTree} from "@/api/archive/bianyan/createTopicLibrary";
import archivesCategory from "@/views/archive/fileCollection/fileRecycleBin/archivesCategory.vue";
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' // 卷详情
import {
  addPublic,
  addSpecial, deletePerson,
  editPublic, editSpecial,
  getArchivesCategory, getPersonList,
  getQueryList,
  getSearchList,
  getShowList, getSpecialList
} from "@/api/archive/bianyan/archiveResources";
import queryCriteriaList from "@/components/queryCriteriaList/index.vue"
import tableList from "@/views/archive/retrieval/catalogueSearch/tableList";
import {getLastIndexOf} from "@/utils";
import {getcateidbyid, getthbytreenodeHeaderList} from "@/api/archive/warehouseManagement/upDownShelves";
import Input from "@/views/archive/retrieval/comprehensiveAdvancedQuery/input"; //不同类型的input 框

export default {
  name: "index",
  mixins: [treeHeight, estimateTableHeight], // 混入方法
  components: { archivesCategory, queryCriteriaList, tableList, jianDetailsOpen, juanDetailsOpen, Input },
  archive_Dicts: ['BGQX', 'MJ'],
  data() {
    return {
      jianDetailsOpen: false,//件详情弹窗
      juanDetailsOpen: false,//卷详情弹窗

      //tabs标签切换默认选择项
      activeName: 'personal',
      showCategory: true,
      archivesCategoryIndex: -1,
      archiveData: [],
      listFrom: [], //查询框列表
      noClick: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        state: '3'
      },
      tableHeaderList: [],
      tableData: [],
      loading: true,
      total: 0,
      showSearch: true,
      keyword: undefined,
      publicIds: '',



      showSpecialSearch: true,
      deptOptions: undefined,
      //默认展开的树节点
      expandedkeys: [],
      //默认选中的树节点
      currentNodekey: "",
      defaultProps: {
        children: "children",
        label: "typeName"
      },
      typeName: undefined,
      isShow: false, //是否显示右侧数据
      specialParams: {
        pageNum: 1,
        pageSize: 10,
        state: '2'
      },
      specialKeyword: undefined,
      specialLoading: true,
      specialTotal: 0,
      specialList: [],
      specialIds: [],
      queryParam: {},

      showPersonalSearch: true,
      personalParams: {
        pageNum: 1,
        pageSize: 10,
        state: '1'
      },
      personalKeyword: undefined,
      personalLoading: true,
      personalTotal: 0,
      personalList: [],
      personalIds: [],
      filename: [],

      // 添加至专题库弹窗
      specialOpen: false,
      treeData: [],
      zhuantiId: undefined,

      size: '',
      size1: '',
      categoryId: ''
    }
  },
  created() {
    if (this.$store.getters.size == 'small') {
      this.size = 'font-size: 12px;'
      this.size1 = 'small'
    } else {
      this.size = 'font-size: 14px;'
      this.size1 = 'medium'
    }
    this.getArchivesCategory()
    this.queryParams.menuId = this.$route.meta.menuId
    if(this.archiveData.length != 0){
      this.archiveData[0].color = '#5377d7';
      this.archiveData[0].backgroundColor = '#e1eaff';
      this.archivesCategoryIndex = 0
    }
  },
  methods: {
    // 点击标签页
    handleClick(tab, event) {
      if(tab.name == "public") {
        this.keyword = undefined
        this.handleQuery()
      } else if(tab.name == 'special') {
        this.getDeptTree()
      } else {
        this.personalKeyword = undefined
        this.getPersonalList()
      }
    },

    //折叠事件
    fold() {
      this.showCategory = false
    },
    //展开事件
    expand(){
      this.showCategory = true
    },
    // 公共库
    getArchivesCategory() {
      getArchivesCategory({menuId:this.$route.meta.menuId}).then(response=>{
        var data = response.data.categoryList.map(item => {
          return {
            // 门类id
            value: item.ID,
            // 门类名称
            label: item.NAME,
            // 元数据方案id
            id: item.GROUP_ID,
            // 类型
            type: item.TYPE,
            color: 'black',
            backgroundColor: 'white'
          }
        })
        var categoryId = response.data.categoryList.map(item => item.ID).toString();
        this.archiveData = []
        this.archiveData = [{
          label: "全部",
          color: 'black',
          backgroundColor: 'white',
          value: categoryId
        }]
        this.archiveData.push(...data)
        if(this.archiveData.length != 0){
          this.archiveData[0].color = '#5377d7';
          this.archiveData[0].backgroundColor = '#e1eaff';
          this.archivesCategoryIndex = 0
        }
        this.queryParams.type = '0'
        this.queryParams.categoryId = categoryId;
        this.categoryId = categoryId
        if (this.activeName == 'personal') {
          this.getPersonalList()
        }
      })
    },
    handleCategory(index, info) {
      if(this.noClick) {
        this.noClick = false;
        if (this.archivesCategoryIndex !== -1) {
          // 恢复上次点击的div为黑色并去掉下划线
          this.archiveData[this.archivesCategoryIndex].color = 'black';
          this.archiveData[this.archivesCategoryIndex].backgroundColor = 'white';
        }
        // 将当前点击的div变为蓝色并添加下划线
        this.archiveData[index].color = '#5377d7';
        this.archiveData[index].backgroundColor = '#e1eaff';

        // 更新archivesCategoryIndex
        this.archivesCategoryIndex = index;
        // 元数据方案id
        this.queryParams.groupId = info.id
        // 门类id
        this.queryParams.categoryId = info.value
        // 门类类型
        this.queryParams.type = '0'
        // label
        this.label = info.label
        this.keyword = undefined
        this.queryParams.queryParameters = undefined
        this.queryParams.fileField = undefined
        // console.log(this.queryParams, '-----------------')
        this.queryParams.pageNum = 1
        this.queryParams.pageSize = 10
        this.queryParam = {};
        if (info.label != '全部') {
          this.getSearch()
        }
        this.listFrom = [] // 查询条件
        this.tableHeaderList = [] // 表头
        this.tableData = [] // 列表数据
        this.total = 0
        this.handleQuery()
      } else {
        this.$message({ message: '重复点击，请稍后再试!', type: 'warning' })
      }
    },
    // 表头
    getTableList() {
      getShowList(this.queryParams).then(response=>{
        if (response.data != undefined) {
          this.tableHeaderList = response.data;
          var fields = []
          for (var i in response.data) {
            fields.push(response.data[i].FIELD_NAME)
          }
          this.queryParams.fileField = fields.toString()
        }
        this.getQuery()
        this.tableHeightData();
        // this.getSearch()
      })
    },
    // 搜索条件
    getSearch() {
      this.listFrom = []
      if(this.queryParams.type != null) {
        getQueryList(this.queryParams).then(response=>{
          if(response.data != undefined) {
            this.listFrom = response.data;
          }
        })
      }
    },
    //是否选择数据
    handleSelectionChange(ids, single, multiple,selection) {
      this.publicIds = selection.map(item => item.ID);
    },
    //排序
    sortChange(val) {
      this.queryParams.order = val;
      this.getQuery();
    },
    // 表格数据
    getQuery() {
      getSearchList(this.queryParams).then(response=>{
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
        this.noClick = true;
      })
    },
    //动态设置table的高度
    tableHeightData() {
      this.$nextTick(
        () => {
          let h = document.documentElement.clientHeight
          h = h - 200
          if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
            h = h - this.$refs.queryForm.$el.offsetHeight
          }
          if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
            h = h - this.$refs.refbut.$el.offsetHeight
          }
          this.tableHeight = h > 580 ? h : 580 // 根据自己项目定高度
          return h
        }
      )
    },
    //表单重置
    resetQuery() {
      this.queryParams.queryParameters = undefined
      this.keyword = undefined
      this.queryParam = {};
      this.queryParams.order = undefined;
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.getTableList();
    },
    //onChangeTap时间
    onChangeTap(data) {
      if (this.queryParam.length > 0) {
        for (var i in this.queryParam) {
          if (Object.keys(this.queryParam[i]).toString() == Object.keys(data).toString()) {
            this.queryParam.splice(i, 1)
          }
        }
        this.queryParam = data;
      } else {
        this.queryParam = data;
      }
    },
    //点击搜索
    handleQuery() {
      this.loading = true;
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParams.order = undefined;
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      var searchcolumn = []
      for (var k in this.listFrom) {
        for (var i in this.queryParam) {
          if(this.queryParam[i] != null) {
            if (this.listFrom[k].FIELD_NAME == i) {
              if (this.listFrom[k].SHOWTYPE == 3&&this.listFrom[k].IS_QUERY==4) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParam[i][0],
                  "valueTwo": this.queryParam[i][1],
                })
              } else if (this.listFrom[k].SHOWTYPE == 7 || this.listFrom[k].SHOWTYPE == 8 || this.listFrom[k].SHOWTYPE == 10) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME+"_ID",
                  "value": this.queryParam[i+"_ID"],
                })
              } else {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParam[i],
                })
              }
            }
          }
        }
      }
      if (searchcolumn != undefined && searchcolumn.length != 0) {
        var column = searchcolumn.filter(item => {
          return item.value !== ''
        })
        this.queryParams.queryParameters = column
      } else {
        this.queryParams.queryParameters = []
      }
      if(this.keyword != "" && this.keyword != undefined){
        const data = [{
          queryType: 8,
          value: this.keyword
        }]
        this.queryParams.queryParameters.push(...data)
      }
      this.queryParams.order = undefined;
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.getTableList()
    },
    // 退回至公共库
    returnPersonal() {
      const id =  this.publicIds
      if (this.publicIds == '') {
        this.$modal.msgWarning('请选择数据退回个人库')
      } else {
        this.form = {
          typeState: '1',
          gerenIds: id
        }
        editPublic(this.form).then(response=>{
          this.$modal.msgSuccess('退回至个人库成功');
          this.getQuery()
        })
      }
    },
    celldblclick(row) {
      var level="";
      var type = "";
      var label = "";
      if (getLastIndexOf(row.sub_table_name) == "F") {  //F 件
        level = 0
        type = "f"
        label = row.TITLE
      } else if (getLastIndexOf(row.sub_table_name) == "V") { //卷
        level = 1
        type = "v"
        label = row.TITLE
      } else { //项目
        level = 3
        type = "x"
        label = row.XMMC
      }
      this.form = {
        id: row.ID,
        type: type
      }
      getcateidbyid(this.form).then(response => {
        var categoryId = response.data
        var menuId = this.$route.meta.menuId
          getthbytreenodeHeaderList(
            {
              categoryId: categoryId, menuId: menuId, subTableName: row.sub_table_name
            }
          ).then(res => {
            var tableHeaderList = res.rows
            this.celldbData = {
              id: row.ID,
              categoryId: categoryId,
              menuId: menuId,
              sub_table_name: row.sub_table_name,
              label: label,
              level: level,
              ifSub_table_name: row.sub_table_name,
              isDel:"0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
              tableHeaderList: tableHeaderList
            }
            this.$nextTick(() => {
              if (getLastIndexOf(row.sub_table_name) == "F") {  //F 进入件详情
                this.jianDetailsOpen = true;
              } else { //进入卷详情 和项目详情
                this.juanDetailsOpen = true
              }
            })
          })
      })
    },
    //关闭详情页面
    detailsHandleClose() {
      this.jianDetailsOpen = false;
      this.juanDetailsOpen = false;
    },


    // 专题树
    getDeptTree() {
      getTree().then(response=>{
        this.deptOptions = response.data
        if (this.deptOptions.length > 0) {
          this.currentNodeKey = this.deptOptions[0].typeId;
          this.expandedkeys.push(this.deptOptions[0].typeId);
          this.$nextTick(() => {
            this.$refs.tree.setCurrentKey(this.deptOptions[0].typeId)
          })
          if(this.currentNodeKey != '0') {
            this.isShow = true
          } else {
            this.isShow = false
          }
        }
      })
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.typeName.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      console.log(data)
      if(data.parentId != '0' && data.typeId != '0' ){
        this.isShow = true
      } else {
        this.isShow = false
      }
      this.specialParams.ztId = data.typeId.toString()
      this.specialKeyword = undefined
      this.getSpecialList()
    },
    handlePublic(row) {
      const id = row.ID || this.personalIds
      if(id.length == 0) {
        this.$modal.msgWarning('请选择至少一条数据提升至公共资料')
      } else {
        this.form = {
          gerenIds: id,
          typeState: '3'
        }
        addPublic(this.form).then(response=>{
          this.getPersonalList();
          this.$modal.msgSuccess("提升至公共资料成功");
        })
      }
    },
    // 专题库查询
    specialQuery() {
      this.specialParams.pageNum = 1
      this.specialParams.pageSize = 10
      this.specialParams.queryParameters = []
      if(this.specialKeyword != "" && this.specialKeyword != undefined){
        const data = [{
          queryType: 8,
          value: this.specialKeyword
        }]
        this.specialParams.queryParameters.push(...data)
      }
      this.getSpecialList()
    },
    // 专题库重置
    specialReset() {
      this.specialKeyword = undefined
      this.resetForm("specialForm");
      this.specialQuery()
    },
    table_index_special(index) {
      return (this.specialParams.pageNum-1) * this.specialParams.pageSize + index + 1;
    },
    specialSelectionChange(selection) {
      this.specialIds = selection.map(item => item.ID)
    },
    // 查询专题库列表
    getSpecialList() {
      this.specialLoading = true
      this.specialParams.categoryId = this.categoryId
      this.specialParams.fileField = 'DH, TITLE, ND, MJ, BGQX'
      getSpecialList(this.specialParams).then(response=>{
        this.specialList = response.rows
        this.specialTotal = response.total
        this.specialLoading = false
        this.noClick = true;
      })
    },
    // 退回至个人库
    returnPerson(row) {
      const id = row.ID || this.specialIds
      if(id.length == 0) {
        this.$modal.msgWarning('请选择至少一条数据退回至个人库')
      } else {
        console.log(id)
        editSpecial(id).then(response=>{
          this.$modal.msgSuccess('退回至个人库成功')
          this.getSpecialList()
        })
      }
    },



    // 个人库查询
    personalQuery() {
      this.personalParams.pageNum = 1
      this.personalParams.pageSize = 10
      this.personalParams.queryParameters = []
      if(this.personalKeyword != "" && this.personalKeyword != undefined){
        const data = [{
          queryType: 8,
          value: this.personalKeyword
        }]
        this.personalParams.queryParameters.push(...data)
      }
      this.getPersonalList()
    },
    // 个人库重置
    personalReset() {
      this.personalKeyword = undefined
      this.resetForm("personalForm");
      this.personalQuery()
    },
    table_index_personal(index){
      return (this.personalParams.pageNum-1) * this.personalParams.pageSize + index + 1;
    },
    // 多选框选中数据
    personalSelectionChange(selection) {
      this.personalIds = selection.map(item => item.ID)
    },
    getPersonalList() {
      this.personalLoading = true
      this.personalParams.categoryId = this.categoryId
      this.personalParams.fileField = 'DH, TITLE, ND, MJ, BGQX'
      getPersonList(this.personalParams).then(response=>{
        this.personalList = response.rows
        this.personalTotal = response.total
        this.personalLoading = false
        this.noClick = true;
      })
    },
    // 删除资料
    handleDelete(row) {
      const id = row.ID || this.personalIds
      const label = row.fileName || this.filename
      if(id.length == 0) {
        this.$modal.msgWarning('请选择至少一条数据进行删除')
      } else {
        this.$modal.confirm('是否确认所选数据项？').then(function() {
          return deletePerson(id)
        }).then(() => {
          this.getPersonalList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      }
    },
    // 转专题库
    handleSpecial(row) {
      const id = row.ID || this.personalIds
      if(id.length == 0) {
        this.$modal.msgWarning('请选择至少一条数据添加至专题库')
      } else {
        getTree().then(response => {
          this.treeData = response.data
          this.specialOpen = true
        })
      }
    },
    specialClick(data) {
      if(data.typeId == '0' || data.parentId == '0') {
        this.$modal.msgWarning('请选择目录层级的节点')
      } else {
        this.zhuantiId = data.typeId
      }
    },
    submitSpecial() {
      console.log(this.zhuantiId)
      if (this.zhuantiId == undefined) {
        this.$modal.msgWarning('请选择专题树节点')
      } else {
        const id = this.personalIds
        this.form = []
        for (let i = 0; i < id.length; i++) {
          this.form.push({
            zhuantiId: this.zhuantiId,
            gerenId: id[i],
            state: '5'
          })
        }
        addSpecial(this.form).then(response=>{
          this.getPersonalList();
          this.specialOpen = false
          this.zhuantiId = undefined
          this.$modal.msgSuccess("添加至专题库成功");
        })
      }
    },
    specialCancel() {
      this.specialOpen = false
    }
  }
}
</script>

<style lang="scss" scoped>
.box-card {
  height: calc(100vh - 190px) !important;
  overflow-y: auto;
}

.showtable {
  margin-top: 2%;
}


.block {
  padding: 3px 8px 3px 8px;
  white-space: nowrap;
  border-radius: 2px;
  border: solid 1px #e3e3e3;
  font-size: 14px;
  text-align: center;
  margin: 0 8px 4px 0;
  display: inline-table;
  line-height: 25px;
}

.searchCheck {
  //margin: 15px auto 0px;
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  line-height: 36px;
  font-size: 14px;
}

.searchCheck .el-input {
  margin-bottom: 10px;
  width: 25%
}
</style>
